<?php
/**
 * Simple registry object class.
 * 
 * LICENSE:
 * 
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with This library. If not, see <{@link http://www.gnu.org/licenses/}>.
 *
 * @link http://code.google.com/p/phpstartapp/
 * @author Bojan Mauser <bmauser@gmail.com>
 * @copyright Bojan Mauser 2009
 * @package psa
 * @version $Id: Psa_Logger.class.php 160 2008-11-30 21:44:05Z bmauser $
 */


/**
 * Simple registry object class.
 * Registry object can be used to store some values or instances to other objects to make them globally accessible.
 * You can use it as storage for data you want make accessible from any scope.
 * In <i>model</i> and <i>view</i> plugins you can access <kbd>Psa_Registry</kbd> object through 
 * reference in local scope.
 * For example, you can add property to <kbd>Psa_Registry</kbd> object in your model method
 * by <code>$this->psa_registry->my_value = '123';</code>
 * It implements {@link http://en.wikipedia.org/wiki/Singleton_pattern singleton pattern}
 * so you can get reference to registry object from any scope with 
 * {@link get_instance()} method. You cannot make instance of Psa_Registry object with 
 * <var>new</var> operator.
 * 
 * <b>Example:</b>
 * 
 * <code>
 * <?php
 * 
 * // controller
 * class Default_Controller extends Psa_Plugin_Controller{
 * 
 * 	function psa_main($args){
 * 
 * 		// new user object
 * 		$user = new Psa_User();
 * 		
 * 		// authorize user
 * 		if(isset($_POST['login_user']) && isset($_POST['login_pass'])){
 * 			$user->username = $_POST['login_user'];
 * 			$user->password = $_POST['login_pass'];
 * 			if($user->authorize()){
 * 				// put reference to user object into registry
 * 				Psa_Registry::get_instance()->user = &$user;
 * 			}
 * 		}
 * 	}
 * }
 * ?>
 * </code>
 * 
 * <code>
 * 
 * <?php
 * 
 * // model
 * class example_model extends Psa_Plugin_Model {
 * 
 * 	function do_something_with_user(){
 * 		
 * 		// in model methods you can access registry object from reference in local scope
 * 		$user = $this->psa_registry->user; // or: $user = Psa_Registry::get_instance()->user;
 * 		$user->is_administrator = true;
 * 		$user->save();
 * 	}
 * }
 * 
 * ?>
 * </code>
 */
class Psa_Registry extends Psa_Singleton {
	
	/**
	 * Returns object's instance.
	 * You should statically call this method with scope resolution operator (::) which gives you
	 * instance to the object from any scope in your application.
	 * Example:
	 * <code>
	 * <?php
	 * 
	 * $registry = Psa_Registry::get_instance();
	 * 
	 * ?>
	 * </code>
	 */
	public static function get_instance($classname = __CLASS__){
		return parent::get_instance($classname);
	}
}


